const enterpriseVue = new Vue({
  el: '#app',
  data() {
    return {
      rules: {
        Approval_Type_Name: [{
          required: true,
          message: '请输入审批类型名称',
          trigger: 'blur',
        }]
      },
      form: {
        Function_Type_SerialNumber: "",
        Function_Type_Name: '',
      },
      dialogImageUrl: '',//图片路径
      dialogVisible: false,//图片是否展示
      loading: false
    }
  },
  mounted() {
    const Function_Type_SerialNumber = sessionStorage.getItem("Function_Type_SerialNumber")
    this.getData(Function_Type_SerialNumber)
  },
  methods: {
    getData(Primary_Key) {
      const _this = this
      $.ajax({
        url: DomainName + `/getInquiryIDOriginal?token=${$.cookie('token')}`,
        type: 'POST',
        data: {
          Data: 'function_type',
          Primary_Key,
          Primary_Key_Name: 'Function_Type_SerialNumber',
          isNullEnterprise: true
        },
        success: function (res) {
          _this.form = res[0]
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      })
    },
    submitForm(formName) {
      let _this = this
      this.$refs[formName].validate((valid) => {
        if (valid) {
          const { add, modify } = _this.deal()
          let data = {}
          if (add == null) {
            data = { Data: JSON.stringify({ Modify: { function_type: [modify] } }), Operation_Name: '修改审批类型' }
          } else {
            data = {
              Data: JSON.stringify({ Modify: { function_type: [modify] }, Add: { function_type: [add] } }),
              Operation_Name: '修改审批类型'
            }
          }
          _this.loading = true
          $.ajax({
            url: DomainName + '/getEditAction?token=' + $.cookie('token'),
            type: 'POST',
            data,
            success: function (res) {
              _this.$message.success("提交成功")
              window.history.go(-1);
            },
            error: function () {
              _this.$message.error("操作失败，请稍后再试")
            },
            complete: function (XMLHttpRequest) {
              _this.loading = false
              if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                window.parent.document.location.href = absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
              }
            }
          })
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    deal() {
      const modify = deepClone(this.form)
      return { add: null, modify };
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  }
})